<template>
  <div style="display: inline-block;text-align: left;">
    <!-- 修改 - btn -->
    <el-button type="primary" icon="el-icon-edit" circle @click="dialogTableVisible = true"/>
    <el-dialog v-el-drag-dialog :visible.sync="dialogTableVisible" width="900px" title="修改" @close="close">
      <el-form ref="row_data" :model="row_data" :rules="rules" label-position="left" label-width="100px" style="width: 750px; margin-left:50px;">
        <el-form-item :label="'id'" prop="id">
          <el-input v-model="row_data.id" placeholder="id" disabled/>
        </el-form-item>
        <el-form-item :label="'商家名称'" prop="merchantName">
          <el-input v-model="row_data.merchantName" placeholder="商家名称"/>
        </el-form-item>
        <el-form-item :label="'申请提现时间'" prop="applyWithdrawTime">
          <el-date-picker v-model="row_data.applyWithdrawTime" type="datetime" value-format="timestamp" placeholder="选择申请提现时间"/>
        </el-form-item>
        <el-form-item :label="'提现状态'" prop="state">
          <el-input v-model="row_data.state" placeholder="提现状态"/>
        </el-form-item>
        <el-form-item :label="'到账时间'" prop="accountingTime">
          <el-date-picker v-model="row_data.accountingTime" type="datetime" value-format="timestamp" placeholder="选择到账时间"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm()">编辑</el-button>
          <el-button @click="close()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
import store from '@/store'
import { edit } from '@/api/merchant/merchant_withdrawal_record'

export default {
  name: 'DragDialogDemo',
  directives: { elDragDialog },
  props: {
    row_data: {
      type: Object,
      default: function() {
        return null
      }
    }
  },
  data() {
    return {
      rules: {
        id: [
          { required: true, message: 'id不能为空', trigger: 'blur' }
        ],
        merchantName: [
          { required: true, message: '商家名称不能为空', trigger: 'blur' }
        ],
        applyWithdrawTime: [
          { type: 'date', required: true, message: '请选择申请提现时间', trigger: 'blur' },
          { required: true, message: '申请提现时间不能为空', trigger: 'blur' }
        ],
        state: [
          { required: true, message: '提现状态不能为空', trigger: 'blur' }
        ],
        accountingTime: [
          { type: 'date', required: true, message: '请选择到账时间', trigger: 'blur' },
          { required: true, message: '到账时间不能为空', trigger: 'blur' }
        ]
      },
      dialogTableVisible: false
    }
  },
  created: function() {
    console.log(this.row_data)
  },
  methods: {
    submitForm() {
      this.$refs.row_data.validate(valid => {
        if (valid) {
          const data = this.row_data
          data.applyWithdrawTime = parseInt(data.applyWithdrawTime / 1000)
          data.accountingTime = parseInt(data.accountingTime / 1000)
          edit(store.getters.token, data).then(res => {
            if (res.status) {
              this.$message.success('修改成功！')
              this.close()
            } else {
              this.$message.error('修改失败！原因：' + res.msg)
            }
          })
        } else {
          return false
        }
      })
    },
    close() {
      this.$emit('getLists')
      this.dialogTableVisible = false
    }
  }
}
</script>
